package com.sky.controller.admin;

import com.github.pagehelper.Page;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.impl.SetmealServiceImpl;
import com.sky.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/setmeal")
public class SetmealController {

    @Resource
    private SetmealServiceImpl setmealService;
    //分页查询
    @GetMapping("/page")
    public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO)
    {
        PageResult page =setmealService.page(setmealPageQueryDTO);
        return Result.success(page);
    }
    //新增套餐
    @CacheEvict
    @PostMapping
    public Result addSetmeal(@RequestBody  SetmealDTO setmealDTO)
    {
        setmealService.addSetmeal(setmealDTO);
        return Result.success();
    }

    //批量删除套餐
    @CacheEvict
    @DeleteMapping
    public Result deletesetmeal(@RequestParam List<Long> ids)
    {
        setmealService.deletesetmeal(ids);
        return Result.success();
    }
    //根据id查询套餐
    @GetMapping("/{id}")
    public Result selectById(Long id)
    {
        SetmealVO setmealVO= setmealService.selectById(id);
        return Result.success();
    }

    //套餐停售or 起售
    @CacheEvict
    @PostMapping("status/{status}")
    public Result status(Integer status ,Long id)
    {
        setmealService.status(status,id);
        return Result.success();
    }

    //修改套餐
    @CacheEvict
    @PutMapping
    public Result updateSetmeal(SetmealDTO setmealDTO){
        setmealService.updateSetmeal(setmealDTO);
        return Result.success();
    }

}
